<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>{:lang('Administrator login')}</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="__STATIC__/bootstrap/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="__STATIC__/font-awesome/css/font-awesome.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="__STATIC__/admin/dist/css/AdminLTE.min.css">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="__STATIC__/admin/dist/js/html5shiv.min.js"></script>
  <script src="__STATIC__/admin/dist/js/respond.min.js"></script>
  <![endif]-->
  <style>
    .login_bg {
        height:auto;
        background: url(__STATIC__/admin/dist/img/login_bg.jpg) repeat center center;
    }
  </style>
</head>
<body class="hold-transition login-page login_bg">
<div class="login-box" style="margin-top:12%;">

  <!-- /.login-logo -->
  <div class="login-box-body">
    <div class="login-logo">
        <h3>{:lang('User login')}</h3>
    </div>

    <form style="padding:30px;">
        <div class="form-group">
          <div class="input-group">
            <span class="input-group-addon"><i class="fa fa-user"></i></span>
            <input type="text" name="username" class="form-control input-sm">
          </div>
        </div>
        <div class="form-group">
          <div class="input-group">
            <span class="input-group-addon"><i class="fa fa-lock"></i></span>
            <input type="password" name="password" class="form-control input-sm">
          </div>
        </div>
        <div class="form-group">
          <div class="input-group">
              <span class="input-group-addon"><i class="fa fa-language"></i></span>
              <select class="form-control input-sm" id="language">
                <option {eq name="lang" value="zh-cn"}selected{/eq} value="zh-cn">简体中文</option>
                <option {eq name="lang" value="en-us"}selected{/eq} value="en-us">English</option>
              </select>
          </div>
        </div>
      <div class="row">
        <div class="col-xs-12">
          <button type="button" onclick="login();" class="btn btn-primary btn-block btn-flat">{:lang('Login')}</button>
        </div>
        <!-- /.col -->
      </div>
    </form>
    <!-- /.social-auth-links -->
  </div>
  <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<!-- jQuery 3 -->
<script src="__STATIC__/jquery/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="__STATIC__/bootstrap/js/bootstrap.min.js"></script>
<!-- Sweetalert 2.1.0 -->
<script src="__STATIC__/sweetalert/promise.min.js"></script>
<script src="__STATIC__/sweetalert/sweetalert.min.js"></script>

<script>
// 语言切换
$(document).ready(function(){

    var lang = $("#language");
    lang.change(function(){
        var opt = lang.val();
        $.ajax({
            type:'post',
            url: "{:url('admin/language/change')}",
            data: {name:lang.val()},
            success: function(r){
                if (r.code == 200) {
                    location.reload();
                }
            }
        });
    });

    // 回车键登录
    document.onkeydown = function (event) {
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if (e && e.keyCode == 13) {
            login();
        }
    };

});

    // 登录
    function login() {
        $.ajax({
            type:'post',
            url: "{:url('admin/passport/login')}",
            data: {username:$("[name='username']").val(),password:$("[name='password']").val()},
            success: function(r){
                if (r.code == 200) {
                    swal({
                      position: 'center',
                      type: 'success',
                      title: r.msg,
                      showConfirmButton: false,
                      toast:true,
                      timer: 1000
                    }).then(function(){
                        window.location.href = "{:url('admin/index/index')}";
                    });
                } else {
                    swal({
                      position: 'center',
                      type: 'error',
                      title: r.msg,
                      showConfirmButton: false,
                      toast:true,
                      timer: 2000
                    })
                }

            
            
            }
        });
    }

</script>
</body>
</html>
